package grape.attend.rest.user.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.attend.rest.user.form.UserLeaveCreateForm;
import grape.attend.rest.user.form.UserLeaveUpdateForm;
import grape.attend.rest.user.form.UserLeaveListPageForm;
import grape.attend.rest.user.vo.UserLeaveVo;
import grape.attend.rest.user.mapper.UserLeaveWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.attend.service.user.po.UserLeave;
import grape.attend.service.user.api.IUserLeaveService;
import java.util.List;
/**
 * <p>
 * 用户请假表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-05-18
 */
@RestController
@RequestMapping("/attend/userleave")
@Api(tags = "用户请假表相关接口")
public class UserLeaveController extends BaseController<UserLeaveVo, UserLeave> {

    @Autowired
    private UserLeaveWebMapper currentWebMapper;
    @Autowired
    private IUserLeaveService currentService;



     @ApiOperation("添加用户请假表")
     @PreAuthorize("hasAuthority('userleave:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public UserLeaveVo create(@RequestBody @Valid UserLeaveCreateForm cf) {
         UserLeave po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询用户请假表")
     @PreAuthorize("hasAuthority('userleave:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public UserLeaveVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除用户请假表")
     @PreAuthorize("hasAuthority('userleave:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新用户请假表")
     @PreAuthorize("hasAuthority('userleave:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public UserLeaveVo update(@PathVariable String id,@RequestBody @Valid UserLeaveUpdateForm uf) {
         UserLeave po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询用户请假表")
    @PreAuthorize("hasAuthority('userleave:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<UserLeaveVo> listPage(UserLeaveListPageForm listPageForm) {
         UserLeave po = currentWebMapper.formToPo(listPageForm);
         return super.listPage(po,listPageForm);
     }

}
